import config from '@/config/wechat'

export const wechatUtils = {
	// 增强版微信环境检测
	isWechatBrowser() {
		const ua = navigator.userAgent.toLowerCase()
		const isMicroMessenger = ua.indexOf('micromessenger') !== -1
		const isWechatDevTools = ua.indexOf('wechatdevtools') !== -1
		const isWorkWechat = ua.indexOf('wxwork') !== -1
		return (isMicroMessenger && !isWorkWechat) || isWechatDevTools
	},

	// 静默授权跳转
	silentAuth() {
		const currentUrl = window.location.href.split('#')[0]
		const redirectUri = encodeURIComponent(currentUrl)
		window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${
      config.appid
    }&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_base&state=wx_auth#wechat_redirect`
	}
}